﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Model;
using DAL;

namespace BLL
{
  public partial  class User_ProductwaterManager
    {
      public IQueryable<User_Productwater> GetByTime(string start, string end, string opertor)
      {
          ZG_OAEntities ds = new ZG_OAEntities();
          var query = from obj in ds.User_Productwater orderby obj.id descending select obj;
          if (!string.IsNullOrEmpty(start) && start != "null")
          {
              DateTime dt = Convert.ToDateTime(start);
              query = from obj in query where obj.ConsDate >= dt orderby obj.id descending select obj;
          }
          if (!string.IsNullOrEmpty(end) && end != "null")
          {
              DateTime dt2 = Convert.ToDateTime(end);
              query = from obj in query where obj.ConsDate <= dt2 orderby obj.id descending select obj;
          }
          if (!string.IsNullOrEmpty(opertor) && opertor != "null")
          {
              if (opertor != "所有操作员")
              {
                  query = from obj in query where obj.admin == opertor orderby obj.id descending select obj;
              }
          }
          return query;
      }
      //根据操作员删除记录
      public bool delByAdmin(string admin)
      {
          IQueryable<User_Productwater> adminAll = null;
          if (admin == "所有操作员")
          {
              adminAll = db.GetAll();
          }
          else
          {
              adminAll = db.GetAll().Where(p => p.admin == admin);
          }
          
         if (admin != null)
         {
             foreach (var item in adminAll)
             {
                 db.Delete(item);
             }
             db.SaveChanges();
             return true;
         }
         else
         {
             return false;
         }
      }
    }
}
